//
//  SLDemo_KVCController.m
//  Objective-C
//
//  Created by S_Line on 2018/6/5.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "SLDemo_KVCController.h"

#import "SLTeacher.h"


@interface SLDemo_KVCController ()

@end

@implementation SLDemo_KVCController

- (void)initNavBar {
    self.navTitle = @"KVC";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavBar];
    
    [self basicFuncs];
}

- (void)basicFuncs {
    SLTeacher *teacher = [[SLTeacher alloc] init];
    teacher.tid = @9;
    teacher.name = @"张三";
    teacher.age = 40;
    
    SLBook *chineseBook = [[SLBook alloc] init];
    chineseBook.bookName = @"语文";
    teacher.book = chineseBook;
    
    id tid = [teacher valueForKey:@"tid"];
    id name = [teacher valueForKeyPath:@"name"];
    id age = [teacher valueForKey:@"age"];
    SLog(@"\n tid: %@\n name: %@\n age: %@", tid, name, age);
    
    id book = [teacher valueForKey:@"book"];
    id bookName1 = [book valueForKey:@"bookName"];
    id bookName2 = [teacher valueForKeyPath:@"book.bookName"];
    SLog(@"\n bookName1: %@\n bookName2: %@", bookName1, bookName2);
    
    NSDictionary *dict = [teacher dictionaryWithValuesForKeys:@[@"tid", @"name", @"age", @"book"]];
    SLog(@"dict: %@", dict);
}

@end
